package androidx.test.espresso.action;

import android.os.Build;
import android.view.KeyEvent;
import androidx.test.espresso.core.internal.deps.guava.base.Preconditions;
import androidx.test.espresso.remote.annotation.RemoteMsgConstructor;
import androidx.test.espresso.remote.annotation.RemoteMsgField;

/* loaded from: classes.dex */
public final class EspressoKey {
    @RemoteMsgField(order = 0)
    private final int keyCode;
    @RemoteMsgField(order = 1)
    private final int metaState;

    private EspressoKey(Builder builder) {
        this(builder.builderKeyCode, builder.getMetaState());
    }

    @RemoteMsgConstructor
    EspressoKey(int keyCode, int metaState) {
        this.keyCode = keyCode;
        this.metaState = metaState;
    }

    public int getKeyCode() {
        return this.keyCode;
    }

    public int getMetaState() {
        return this.metaState;
    }

    public String toString() {
        return String.format("keyCode: %s, metaState: %s", Integer.valueOf(this.keyCode), Integer.valueOf(this.metaState));
    }

    /* loaded from: classes.dex */
    public static class Builder {
        private int builderKeyCode = -1;
        private boolean isAltPressed;
        private boolean isCtrlPressed;
        private boolean isShiftPressed;

        public Builder withKeyCode(int keyCode) {
            this.builderKeyCode = keyCode;
            return this;
        }

        public Builder withShiftPressed(boolean shiftPressed) {
            this.isShiftPressed = shiftPressed;
            return this;
        }

        public Builder withCtrlPressed(boolean ctrlPressed) {
            this.isCtrlPressed = ctrlPressed;
            return this;
        }

        public Builder withAltPressed(boolean altPressed) {
            this.isAltPressed = altPressed;
            return this;
        }

        /* JADX INFO: Access modifiers changed from: private */
        public int getMetaState() {
            int i = this.isShiftPressed ? 1 : 0;
            if (this.isAltPressed) {
                i |= 2;
            }
            return (!this.isCtrlPressed || Build.VERSION.SDK_INT < 11) ? i : i | 4096;
        }

        public EspressoKey build() {
            int i = this.builderKeyCode;
            Preconditions.checkState(i > 0 && i < KeyEvent.getMaxKeyCode(), "Invalid key code: %s", this.builderKeyCode);
            return new EspressoKey(this);
        }
    }
}
